package com.imoblife.brainwavestus.receiver;

import com.imoblife.brainwavestus.model.Constant;
import com.imoblife.brainwavestus.util.DebugUtil;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageButton;

public class UpdateTitleViewReceiver extends BroadcastReceiver {
	
	public static final String TAG = "UpdateTitleViewReceiver";
	
	public ImageButton mSubScriptionButton;
	
	public ImageButton mMySubScriptionButton;
	
	public UpdateTitleViewReceiver(ImageButton sub, ImageButton mySub) {
		
		mSubScriptionButton = sub;
		
		mMySubScriptionButton = mySub;
	}
	
	public void onReceive(Context context, Intent intent) {
		
		if(!checkIsButtonInit()) {
			
			DebugUtil.receiverDebug(TAG, "button not initial!!!");
			
			return;		
		}
		
		if (intent.getAction().equals(
				Constant.UPDATE_STATEVIEW_MYSUBSCRIPTION)) {
			
			DebugUtil.receiverDebug(TAG, "show My SubScription window");
			
			mMySubScriptionButton.setVisibility(View.VISIBLE);
			mSubScriptionButton.setVisibility(View.GONE);

		} else if (intent.getAction().equals(
				Constant.UPDATE_STATEVIEW_SUBSCRIPTION)) {
			
			DebugUtil.receiverDebug(TAG, "show Sub Scription window");
			
			mMySubScriptionButton.setVisibility(View.GONE);
			mSubScriptionButton.setVisibility(View.VISIBLE);
		}
	}
	
	private boolean checkIsButtonInit(){
		
		return (mSubScriptionButton != null) 
				   && (mMySubScriptionButton != null);
	}
}
